package com.aw.guiguzi.module.setting

import android.view.View
import android.widget.CompoundButton
import android.widget.Switch
import android.widget.TextView
import com.aw.baselib.base.AwBaseBindingActivity
import com.aw.baselib.base.AwBaseEvent
import com.aw.guiguzi.R
import com.aw.guiguzi.databinding.ActivitySettingBettingBinding
import com.aw.guiguzi.event.EventRefreshBettingCustomType
import com.aw.guiguzi.util.AppCacheUtil

class SettingBettingActivity : AwBaseBindingActivity<ActivitySettingBettingBinding?>() {
    override fun refreshByBus(type: AwBaseEvent) {
        super.refreshByBus(type)
        if (type is EventRefreshBettingCustomType) {
            setText(binding?.tvBettingCustom, AppCacheUtil.getBettingCustom())
        }
    }

    override fun getViewBinding(): ActivitySettingBettingBinding {
        return ActivitySettingBettingBinding.inflate(layoutInflater)
    }

    override fun initView() {
        super.initView()
        setToolbar("投注设置", null)
    }

    override fun initData() {
        super.initData()
        binding?.switchBettingDefault?.isChecked = AppCacheUtil.isBettingDefault()
        binding?.switchBettingReConfirm?.isChecked = AppCacheUtil.isBettingReConfirm()
        setText(binding?.tvBettingCustom, AppCacheUtil.getBettingCustom())
    }

    override fun initListener() {
        super.initListener()
        binding?.switchBettingDefault?.setOnCheckedChangeListener { _: CompoundButton?, isChecked: Boolean ->
            if (isChecked) {
                AppCacheUtil.setBettingDefault(true)
                showMsg("自动下注已选择组合已启用")
            } else {
                AppCacheUtil.setBettingDefault(false)
                showMsg("自动下注已选择组合已禁用")
            }
        }
        binding?.switchBettingReConfirm?.setOnCheckedChangeListener { _: CompoundButton?, isChecked: Boolean ->
            if (isChecked) {
                AppCacheUtil.setBettingReConfirm(true)
                showMsg("下注后再次确认已启用")
            } else {
                AppCacheUtil.setBettingReConfirm(false)
                showMsg("下注后再次确认已禁用")
            }
        }
        binding?.llBettingCustom?.setOnClickListener {
            toClass(
                SettingBettingCustomEditActivity::class.java, false
            )
        }
    }
}